package com.ruibei.ui.fragment;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

import com.ruibei.R;
import com.ruibei.models.SendApprovalModel;
import com.ruibei.utils.BaseViewHolder;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 申请的审批
 *
 * @author limingyan
 *
 */
public class ApprovalSendFragment extends BaseFragment{
	
	@InjectView(R.id.send_apply_list)
	ListView mListView;
	
	private View mBaseView;
	private MyListAdapter myListAdapter;
	@Override
	public View onCreateView(LayoutInflater inflater,
			 ViewGroup container, Bundle savedInstanceState) {
		mBaseView = inflater.inflate(R.layout.fragment_approval_send, container,
				false);
		ButterKnife.inject(this, mBaseView);
		
		setUpView();
		return mBaseView;
	};
	
	private void setUpView(){
		
		//以下测试数据
		SendApprovalModel model = new SendApprovalModel("黄总");
		SendApprovalModel model2 = new SendApprovalModel("李总");
		ArrayList<SendApprovalModel> arr = new ArrayList<SendApprovalModel>();
		arr.add(model);
		arr.add(model2);
		myListAdapter = new MyListAdapter(arr);
		mListView.setAdapter(myListAdapter);
	}
	
	//申请列表适配器
	public class MyListAdapter extends BaseAdapter{
		ArrayList<SendApprovalModel> mList;
		private LayoutInflater mInflater;
		
		public MyListAdapter(ArrayList<SendApprovalModel> arr) {
			// TODO Auto-generated constructor stub
			mInflater = LayoutInflater.from(getActivity());
			mList = arr;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mList==null?0:mList.size();
		}

		@Override
		public SendApprovalModel getItem(int position) {
			// TODO Auto-generated method stub
			return mList.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return getItem(position).id;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = mInflater.inflate(R.layout.list_item_apply, null);
			}
			TextView tvName = BaseViewHolder.get(convertView, R.id.apply_name);
			
			final SendApprovalModel bean = getItem(position);
			tvName.setText(bean.name);
			return convertView;
		}
	}
}
